﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace DataAccess
{
    /// <summary>
    /// 数据访问类:TB_CHECK
    /// </summary>
    public partial class TB_CHECK
    {
        public TB_CHECK()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(decimal NID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TB_CHECK");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Add(Model.TB_CHECK model)
        {
            model.NID = CommonExecute.GetID(model.GetType().Name);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TB_CHECK(");
            strSql.Append("NID,SQDH,CSQMC,YPSFKD,WZXJC,YZXJC,ZTJL,CREATE_USER,CREATE_DATE,STATE)");
            strSql.Append(" values (");
            strSql.Append(":NID,:SQDH,:CSQMC,:YPSFKD,:WZXJC,:YZXJC,:ZTJL,:CREATE_USER,:CREATE_DATE,:STATE)");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,10),
					new OracleParameter(":SQDH", OracleType.Number,10),
					new OracleParameter(":CSQMC", OracleType.NVarChar),
					new OracleParameter(":YPSFKD", OracleType.Number,1),
					new OracleParameter(":WZXJC", OracleType.Number,1),
					new OracleParameter(":YZXJC", OracleType.Number,1),
					new OracleParameter(":ZTJL", OracleType.Number,1),
					new OracleParameter(":CREATE_USER", OracleType.NVarChar),
					new OracleParameter(":CREATE_DATE", OracleType.DateTime),
                    new OracleParameter(":STATE", OracleType.Number,10),};
            parameters[0].Value = model.NID;
            parameters[1].Value = model.SQDH;
            parameters[2].Value = model.CSQMC;
            parameters[3].Value = model.YPSFKD;
            parameters[4].Value = model.WZXJC;
            parameters[5].Value = model.YZXJC;
            parameters[6].Value = model.ZTJL;
            parameters[7].Value = model.CREATE_USER;
            parameters[8].Value = model.CREATE_DATE;
            parameters[9].Value = model.STATE;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool Update(Model.TB_CHECK model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update TB_CHECK set ");
            strSql.Append("SQDH=:SQDH,");
            strSql.Append("CSQMC=:CSQMC,");
            strSql.Append("YPSFKD=:YPSFKD,");
            strSql.Append("WZXJC=:WZXJC,");
            strSql.Append("YZXJC=:YZXJC,");
            strSql.Append("ZTJL=:ZTJL,");
            strSql.Append("CREATE_USER=:CREATE_USER,");
            strSql.Append("CREATE_DATE=:CREATE_DATE,");
            strSql.Append("STATE=:STATE");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":SQDH", OracleType.Number,10),
					new OracleParameter(":CSQMC", OracleType.NVarChar),
					new OracleParameter(":YPSFKD", OracleType.Number,1),
					new OracleParameter(":WZXJC", OracleType.Number,1),
					new OracleParameter(":YZXJC", OracleType.Number,1),
					new OracleParameter(":ZTJL", OracleType.Number,1),
					new OracleParameter(":CREATE_USER", OracleType.NVarChar),
					new OracleParameter(":CREATE_DATE", OracleType.DateTime),
					new OracleParameter(":NID", OracleType.Number,10),
                    new OracleParameter(":STATE", OracleType.Number,10)};
            parameters[0].Value = model.SQDH;
            parameters[1].Value = model.CSQMC;
            parameters[2].Value = model.YPSFKD;
            parameters[3].Value = model.WZXJC;
            parameters[4].Value = model.YZXJC;
            parameters[5].Value = model.ZTJL;
            parameters[6].Value = model.CREATE_USER;
            parameters[7].Value = model.CREATE_DATE;
            parameters[8].Value = model.NID;
            parameters[9].Value = model.STATE;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static bool Delete(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_CHECK ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public static bool DeleteList(string NIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_CHECK ");
            strSql.Append(" where NID in (" + NIDlist + ")  ");
            int rows = DbHelperOra.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Model.TB_CHECK GetModel(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,SQDH,CSQMC,YPSFKD,WZXJC,YZXJC,ZTJL,CREATE_USER,CREATE_DATE,STATE from TB_CHECK ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            Model.TB_CHECK model = new Model.TB_CHECK();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SQDH"] != null && ds.Tables[0].Rows[0]["SQDH"].ToString() != "")
                {
                    model.SQDH = decimal.Parse(ds.Tables[0].Rows[0]["SQDH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CSQMC"] != null && ds.Tables[0].Rows[0]["CSQMC"].ToString() != "")
                {
                    model.CSQMC = ds.Tables[0].Rows[0]["CSQMC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["YPSFKD"] != null && ds.Tables[0].Rows[0]["YPSFKD"].ToString() != "")
                {
                    model.YPSFKD = decimal.Parse(ds.Tables[0].Rows[0]["YPSFKD"].ToString());
                }
                if (ds.Tables[0].Rows[0]["WZXJC"] != null && ds.Tables[0].Rows[0]["WZXJC"].ToString() != "")
                {
                    model.WZXJC = decimal.Parse(ds.Tables[0].Rows[0]["WZXJC"].ToString());
                }
                if (ds.Tables[0].Rows[0]["YZXJC"] != null && ds.Tables[0].Rows[0]["YZXJC"].ToString() != "")
                {
                    model.YZXJC = decimal.Parse(ds.Tables[0].Rows[0]["YZXJC"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ZTJL"] != null && ds.Tables[0].Rows[0]["ZTJL"].ToString() != "")
                {
                    model.ZTJL = decimal.Parse(ds.Tables[0].Rows[0]["ZTJL"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CREATE_USER"] != null && ds.Tables[0].Rows[0]["CREATE_USER"].ToString() != "")
                {
                    model.CREATE_USER = ds.Tables[0].Rows[0]["CREATE_USER"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_DATE"] != null && ds.Tables[0].Rows[0]["CREATE_DATE"].ToString() != "")
                {
                    model.CREATE_DATE = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["STATE"] != null && ds.Tables[0].Rows[0]["STATE"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["STATE"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,SQDH,CSQMC,YPSFKD,WZXJC,YZXJC,ZTJL,CREATE_USER,CREATE_DATE,STATE ");
            strSql.Append(" FROM TB_CHECK ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataTable GetList(string strWhere, int startRecord, int maxRecords)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,SQDH,CSQMC,YPSFKD,WZXJC,YZXJC,ZTJL,CREATE_USER,CREATE_DATE,STATE ");
            strSql.Append(" FROM TB_CHECK ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }

            return DbHelperOra.Query(strSql.ToString(), startRecord, maxRecords);
        }

        /// <summary>
        /// 获取记录数
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public static int GetCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) num ");
            strSql.Append(" FROM TB_CHECK ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperOra.GetSingle(strSql.ToString());
            return int.Parse(obj.ToString());
        }
        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "TB_CHECK";
            parameters[1].Value = "NID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

